package yao.com.exp3.activity;

import android.content.Intent;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;

import yao.com.exp3.Constant.StringConstant;
import yao.com.exp3.R;
import yao.com.exp3.util.HttpCallbackListener;
import yao.com.exp3.util.HttpUtil;
import yao.com.exp3.util.LogUtil;
import yao.com.exp3.util.StringUtil;
import yao.com.exp3.Constant.StringConstant;

public class RegisterActivity extends AppCompatActivity {


    private EditText edt_register_username;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        initView();
    }

    private void initView() {
        edt_register_username=(EditText)findViewById(R.id.editText);
    }

    public void onClickRegister_submit(View view){
        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
        startActivity(intent);
//        onRegister_submit();
    }

    public void onRegister_submit(){
        //取得用户输入的账号和密码
        if (TextUtils.isEmpty(edt_register_username.getText().toString())) {
            Toast.makeText(RegisterActivity.this, "未输入XXXX", Toast.LENGTH_SHORT).show();
        }
        else{

            String username = edt_register_username.getText().toString();

            if (StringUtil.checkString(username)) {
              /*
                    将所有信息放入一个User类

              */
                try {
               /*
                      和登陆一样 进入HttpUtil将信息封装成一个URL
                       String compeletedURL = HttpUtil.getURLWithParams(StringConstant.ori_url, params);
               */
               /*
                       再将这个URL发送给服务器
               */
                    HttpUtil.sendHttpRequest(StringConstant.ori_url, new HttpCallbackListener() {

                        public void onResult(String s) {
                            // 服务端返回Json
                            LogUtil.d(RegisterActivity.this, "登陆服务器返回数据： " + s, "" + 94);
                            if ("null".equals(s)) {
                                Toast.makeText(RegisterActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
                                return;
                            }

                        }

                        @Override
                        public void onError(Exception e) {
                            /*错误时处理*/
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            else{
                Toast.makeText(RegisterActivity.this, "XXX填写不符合要求", Toast.LENGTH_SHORT).show();
            }

        }
    }
}
